******Master headteacher monitoring do file****
******Purpose: To run all the cleaning do files for the headteacher monitoring survey
******and save a clean data set
******Last modified: 4th April 2019****

clear all
cap log close

do "[directory]/02 HeadTeacher_Survey_Cleaning.do"
do "[directory]/03 HeadTeacher_Survey_Correction.do"


save "[directory]/headteacher_endline_clean.dta", replace

clear all

use "[directory]/headteacher_endline_clean.dta", clear

	local piivars first_name_200 family_name_200 name_209__1 name_209__2 name_209__3 name_209__4 name_209__5
	local piinum -99999
	local piistr NONPII VERSION
	generate piiid = _n
	ds `piivars', has(type numeric)
	foreach var in `r(varlist)' {
		replace `var' = `piinum' if !missing(`var')
	}
	ds `piivars', has(type string)
	foreach var in `r(varlist)' {
		replace `var' = "`piistr'" if !inlist(`var', "", "don't know", "refusal")
	}

save "[directory]/headteacher_endline_clean_NOPIIs.dta", replace
